/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package UnitTest;

import junit.framework.TestCase;
import Model.Inscricao;
import DB.DBManager;
import DB.Inscricao.ControllerInscricao;
import java.sql.SQLException;
import static junit.framework.TestCase.assertEquals;

/**
 *
 * @author KZA
 */
public class TesteInscricao extends TestCase {
    
    DBManager db;
    
    public TesteInscricao(String testName, DBManager db) {
        super(testName);
        this.db = db;
    }

    public void testeInscricao(long eventId, long userId) {
        System.out.println("* Unit_Test: I testeInscricao");

        Inscricao insc = new Inscricao(eventId, userId, "01092013");

        assertEquals(userId,        insc.getIdParticipante());
        assertEquals(eventId,       insc.getIdEvento());
        assertEquals("01092013",    insc.getDataInscricao());
        
        System.out.println("* Unit_Test: F testeInscricao");
    }

    public long testeInsertInscricaoBanco(long eventId, long userId) throws SQLException, ClassNotFoundException {
        System.out.println("* Unit_Test: I testeInsertInscricaoBanco");
        
        ControllerInscricao ic = ControllerInscricao.getInstance();
        int count = db.getTableCount("Inscricoes");
        Inscricao insc = new Inscricao(eventId, userId, "01092013");
        long id = ic.inscricao(insc);

        assertEquals(count+1, db.getTableCount("Inscricoes"));
        
        System.out.println("* Unit_Test: F testeInsertInscricaoBanco");
        return id;
    }
    
    public void testeUpdateInscricaoBanco(long id, long eventId, long userId) throws SQLException {
        System.out.println("* Unit_Test: I testUpdateInscricaoBanco");
        
        ControllerInscricao ic = ControllerInscricao.getInstance();
        int count = db.getTableCount("Inscricoes");
        Inscricao insc = new Inscricao(eventId, userId, "30092013");
        insc.setId(id);
        long n = ic.update(insc);

        assertEquals(n, 1);
        assertEquals(count, db.getTableCount("Inscricoes"));

        System.out.println("* Unit_Test: F testUpdateInscricaoBanco");
    }
    
    public void testeSelectInscricaoBanco(long id, long eventId, long userId) throws SQLException {
        System.out.println("* Unit_Test: I testSelectInscricaoBanco");

        Inscricao insc = new Inscricao();
        
        ControllerInscricao ic = ControllerInscricao.getInstance();
        
        insc = ic.getByID(id);
        
        assertEquals(userId,        insc.getIdParticipante());
        assertEquals(eventId,       insc.getIdEvento());
        assertEquals("30092013",    insc.getDataInscricao());
        
        System.out.println("* Unit_Test: F testSelectInscricaoBanco");
    }
}
